class Solution
{
public:
    int findSmallestInteger(vector<int> &nums, int value)
    {
        unordered_map<int, int> modCount;
        for (int num : nums)
        {
            if (num < 0) // 要防止负数
            {
                num += (((-num) / value) + 1) * value;
            }
            ++modCount[num % value];
        }

        int mex = 0;
        while (true)
        {
            if (modCount[mex % value] > 0)
            {
                --modCount[mex % value];
                ++mex;
            }
            else
            {
                break;
            }
        }
        return mex;
    }
};